package cn.rengy.web.framework.sys.worker;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.hutool.core.net.NetUtil;
import cn.rengy.web.framework.sql.DbService;

@Service
public class SysWorkerNodeService {
	@Autowired
	private DbService dbService;
	
	public int getWorkerId() {
		String ip=NetUtil.getLocalhostStr();
		String hostname=NetUtil.getLocalHostName();
		Integer workerid=dbService.querySingleColumn("select_unique_worker", Integer.class, hostname);
		if(workerid==null) {
			//新增
			Map<String,Object> insert=new HashMap<String,Object>(5,1);
			insert.put("hostname", hostname);
			insert.put("ip", ip);
			insert.put("create_time", new Date());
			workerid= dbService.updateReturnGeneratedKeys("insert_sys_worker_node", insert).intValue();
		}
		return workerid;
	}
}
